package com.ld.shieldsb.common.core.util.properties;

import java.io.UnsupportedEncodingException;

import org.apache.commons.configuration2.PropertiesConfiguration;

import com.ld.shieldsb.common.core.util.StringUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * 参数管理类,在后期的版本中将删除，替换类为ConfigPropertiesUtil替换，可以使用ConfigFileBuilder.build("config.properties【文件路径】")来获取对应的类
 * 
 * @ClassName PropertiesUtil
 * @author <a href="mailto:donggongai@126.com" target="_blank">kevin</a>
 * @date 2014-6-21 下午2:37:40
 * 
 */
@Slf4j
@Deprecated
public class PropertiesUtil extends ConfigAbstractUtil<PropertiesConfiguration> {

    public PropertiesUtil(String fileName) {
        super(fileName);
    }

    @Override
    protected String getComment(PropertiesConfiguration configuration, String key) {
        String comment = configuration.getLayout().getComment(key);
        if (comment != null) {
            try {
                comment = new String(comment.getBytes("iso-8859-1"));
            } catch (UnsupportedEncodingException e) {
                log.error("编码异常", e);
            }
            comment = comment.replace("#", "");
        }
        return comment;
    }

    @Override
    protected void saveComment(String key, String comment, PropertiesConfiguration configuration) {
        if (StringUtils.isNotBlank(comment)) {
            String commentVal = comment;
            try {
                commentVal = new String(comment.getBytes(), "iso-8859-1");
            } catch (UnsupportedEncodingException e) {
                log.error("", e);
            }
            configuration.getLayout().setComment(key, commentVal);
        }

    }

}
